package org.originit.factory.core.io;

import cn.hutool.core.lang.Assert;

import java.net.MalformedURLException;
import java.net.URL;

public class DefaultResourceLoader implements ResourceLoader{
    @Override
    public Resource getResource(String location) {
        Assert.notNull(location,"location must not be null");
        if (location.startsWith(ResourceLoader.CLASS_PATH_PREFIX)) {
            return new ClassPathResource(location.substring(ResourceLoader.CLASS_PATH_PREFIX.length()));
        }
        try {
            URL url = new URL(location);
            URLResource urlResource = new URLResource(url);
            return urlResource;
        } catch (MalformedURLException e) {
            return new FileSystemResource(location);
        }
    }
}
